package com.example.demo.service.warehouse;


import com.example.demo.dao.warehouse.WarehouseDAO;
import com.example.demo.model.warehouse.Warehouse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WarehouseService {
    @Autowired
    private WarehouseDAO dao;

    public Boolean save(Warehouse warehouse) {
        Boolean flag = false;

        if (warehouse.getWarehouse_id() != null) {
            flag = dao.updateById(warehouse) == 1;
        } else {
            flag = dao.addWarehouse(warehouse) == 1;
        }

        return flag;
    }

    //    查询全部
    public List<Warehouse> selectAll() {
        return dao.selectAll();
    }

    //    添加数据
    public Integer addWarehouse(Warehouse warehouse) {
        return dao.addWarehouse(warehouse);
    }

    //删除数据
    public Integer deleteById(Integer warehouse_id) {
        return dao.deleteById(warehouse_id);
    }

    //更新
    public Integer updateById(Warehouse warehouse) {
        return dao.updateById(warehouse);
    }

    public Integer updateProductNumberById(Integer number, Integer product_id) {
        return dao.updateProductNumberById(number, product_id);
    }

    public Integer AddProductNumberById(Integer number, Integer product_id) {
        return dao.AddProductNumberById(number, product_id);
    }

    public List<Warehouse> findWarehouse(Integer product_id, Integer provider_id) {
        return dao.findWarehouse(product_id, provider_id);
    }
}
